package com.ds.springbootmybatis.controller;

import com.ds.springbootmybatis.mapper.DepartmentMapper;
import com.ds.springbootmybatis.pojo.Department;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: SpringBoot
 * @description:
 * @author: Dawson.Zhang
 * @create: 2020-05-12
 **/
@Controller
public class DeptController {
    @Resource
    DepartmentMapper departmentMapper;

    @GetMapping("/hello")
    public String get(){
        return "success";
    }
    @GetMapping("/dept/{id}")
    @ResponseBody
    public Department getDept(@PathVariable("id") Integer id){
        Department byId = departmentMapper.getById(id);
        return byId;
    }
    @GetMapping("/depts")
    @ResponseBody
    public List<Department> getDepts(){
        List<Department> all = departmentMapper.getAll();
        return all;
    }
    @DeleteMapping("/dept/{id}")
    @ResponseBody
    public Integer delId(@PathVariable("id") Integer id){
        Integer integer = departmentMapper.deleteById(id);
        return integer;
    }
    @PostMapping("/dept")
    @ResponseBody
    public Department addDept(Department department){
        departmentMapper.addDept(department);
        return  department;
    }
    @PutMapping("/dept")
    @ResponseBody
    public Integer updateDept(Department department){
        Integer integer = departmentMapper.updateDept(department);
        return integer;
    }
}
